<template>
  <!-- 看点列表 -->
  <div class="box" v-loading.fullscreen.lock="loading" element-loading-text="拼命加载中"
    element-loading-background="rgba(255, 255, 255, 0.8)">
    <div v-show="!loading">
      <heads></heads>
      <secondHead customEvent @search="search"></secondHead>
      <div class="bottom" style="position: relative; width: 1000px; margin: 0 auto">
        <div @click.stop="
          checkLogin(() => {
            openUrlb('/release/releaseCircleFriends');
          })
          " style="
            position: absolute;
            height: auto;
            width: 36px;
            height: 26px;
            top: -32px !important;
            right: 16px;
            background-color: #64b6a8;
            text-align: center;
            border-radius: 2px;
            cursor: pointer;
          ">
          <img style="height: auto; width: 20px" src="https://pic.bangbangtongcheng.com/static/bbcz/sell_byq02.png" />
        </div>

        <template v-for="(s, i) in ceshiArr">
          <bbczFriendCircleItem :item="s" :key="s.id" :i="i" :mySelf="true" @reData="friendsCircle()"></bbczFriendCircleItem>
        </template>
        <div class="gotop" @click="toTop" v-show="showToTop" style="right: calc((100vw / 2) - 600px)">
          <img src="../../assets/top.png" />返回顶部
        </div>
        <el-empty v-if="ceshiArr.length == 0"></el-empty>
        <div class="fenye">
          <el-pagination background layout="prev, pager, next" :total="housetotal" :page-size="housePage.pageSize"
            :current-change="housePage.pageNo" @current-change="currenthouse"></el-pagination>
        </div>
      </div>
      <floor></floor>
    </div>
  </div>
</template>
<script>
import floor from "../../components/floor";
import heads from "../../components/head";
import packUpText from "./comp/packUpText.vue";
import bbczFriendCircleItem from "./comp/bbcz-friend-circle-item";
export default {
  components: {
    floor,
    heads,
    packUpText,
    bbczFriendCircleItem,
  },
  data() {
    return {
      loading: true,
      showToTop: false,
      img: this.$img,
      searchtext: "",
      housePage: {
        pageSize: 10,
        pageNo: 1,
      },
      houseList: [],
      housetotal: 0,
      ceshiArr: [],
    };
  },

  created() {
    this.getUser();
    this.init();
    this.handleScroll();
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll, true);
  },
  methods: {
    toTop() {
      let top = document.documentElement.scrollTop || document.body.scrollTop;
      // 实现滚动效果
      const timeTop = setInterval(() => {
        document.body.scrollTop =
          document.documentElement.scrollTop =
          top -=
          50;
        if (top <= 0) {
          clearInterval(timeTop);
        }
      }, 10);
    },
    handleScroll() {
      let scrolltop =
        document.documentElement.scrollTop || document.body.scrollTop;
      scrolltop > 30 ? (this.showToTop = true) : (this.showToTop = false);
    },
    init() {
      this.friendsCircle();
    },
    friendCircleDetail(item) {
      this.openUrl({
        path: "/my/friendsCircleDetails",
        query: {
          id: item.id,
        },
      });
    },
    search(searchtext) {
      this.keyword = searchtext;

      this.housePage.pageNo = 1;
      this.friendsCircle();
    },
    // 获取帮友圈数据
    friendsCircle() {
      this.$getHttp("/api/mobile/vehicleOwner/queryHelpingFriendsCircleList", {
        ...this.housePage,
        keyword: this.keyword || "",
        publisherId: this.loginstate
          ? JSON.parse(localStorage.getItem("userInfo")).id
          : "",
      }).then((data) => {
        //auditStatus  string审核状态（0：待审核，1：已通过，2：已拒绝）
        if (data.code == 200) {
          data.helpingFriendsCircleList.pageList.forEach((item) => {
            item.chage = 0;
            item.picture = this.manageImg(item.picture);
            item.imageList = this.manageImg(item.picture);
            item.video = this.manageImg(item.video);
            console.log(
              "=====>",
              "item.imageListitem.imageList",
              item.imageList
            );
          });
          setTimeout(() => {
            this.loading = false;
          }, 100);
          this.ceshiArr = data.helpingFriendsCircleList.pageList;
          this.housetotal = data.helpingFriendsCircleList.pageCount;
          // console.log('this.ceshiArr',this.ceshiArr)
        }
      });
    },
    //处理图片
    manageImg(imgs) {
      var arr = [];
      if (null != imgs) {
        if (imgs.indexOf("|") == -1) {
          if (imgs != "") {
            arr.push(imgs);
            // console.log("imgs", arr);
            return arr;
          } else {
            return [];
          }
        } else {
          return imgs.split("|");
        }
      }
    },

    getUser() {
      let user = JSON.parse(localStorage.getItem("userInfo"));
      if (user != null) {
        this.loginstate = true;
      } else {
        this.loginstate = false;
      }
    },
    // 关注
    collect(item, flag) {
      if (this.loginstate) {
        this.$postHttp(
          "/api/mobile/vehicleOwner/collectionOrCancelCollection",
          {
            collectorId: JSON.parse(localStorage.getItem("userInfo")).id,
            collectionType: 3,
            relationId: item.id,
            id:
              item.collectionAttention && item.collectionAttention.id
                ? item.collectionAttention.id
                : "",
          }
        ).then((data) => {
          if (data.code == 200) {
            this.friendsCircle();
            this.$message({
              message: data.msg,
              type: "success",
              offset: 120,
              duration: 2000,
            });
          }
        });
      } else {
        this.$message({
          message: "请登录之后在收藏个人！",
          type: "error",
          offset: 120,
          duration: 2000,
        });
      }
    },
    // 根据发布人ID获取帮友圈信息列表
    // getHelpingFriendsCircleByPublisher(){
    // /api/mobile/vehicleOwner/getHelpingFriendsCircleByPublisher

    // },
    goLike(item, flag) {
      if (this.loginstate) {
        // 去关注
        var obj = {
          userId: JSON.parse(localStorage.getItem("userInfo")).id,
          circleId: item.id,
        };
        item.likeRecord && item.likeRecord.id
          ? (obj.id = item.likeRecord.id)
          : "";
        this.$postHttp("/api/mobile/vehicleOwner/upperOrCancelThumb", {
          // id: item.id,
          ...obj,
        }).then((data) => {
          if (data.code == 200) {
            this.friendsCircle();
            this.$message({
              message: data.msg,
              type: "success",
              offset: 120,
              duration: 2000,
            });
          }
        });
      } else {
        this.$message({
          message: "请登录之后在收藏个人！",
          type: "error",
          offset: 120,
          duration: 2000,
        });
      }
    },
    zhankaiClick(item) {
      this.ceshiArr.forEach((v) => {
        if (v.id == item.id) {
          if (v.chage == 0) {
            v.chage = 1;
          } else {
            v.chage = 0;
          }
        }
      });
    },
    currenthouse(e) {
      this.scrollToElement(document.querySelector(".bottom"));
      this.housePage.pageNo = e;
      this.ceshiArr = [];
      this.friendsCircle();
    },
  },
};
</script>
<style lang="less" scoped>
.box {
  position: relative;
  padding-bottom: 200px;
}

.tit1 {
  width: 100%;
  height: 120px;
  background-color: #f2f2f2;

  .list {
    width: 1200px;
    margin-left: 50%;
    padding-top: 32px;
    transform: translateX(-50%);
    background-color: #f2f2f2;

    div {
      display: inline-block;
      vertical-align: middle;
      font-size: 20px;
      color: #333333;
      margin-right: 40px;
      cursor: pointer;
    }

    .li {
      font-size: 28px;
      color: #64b6a8;
      margin-right: 60px;

      img {
        /* width: 60px;
        height: 60px; */
      }

      span {
        vertical-align: middle;
      }
    }

    .sousuo {
      position: relative;
      display: inline-block;
      vertical-align: middle;
      width: 380px;
      height: 50px;
      background: #ffffff;
      border-radius: 4px;
      font-size: 18px;
      overflow: hidden;

      input {
        width: 300px;
        height: 55px;
        line-height: 55px;
        text-indent: 16px;
        font-size: 18px;
      }

      img {
        width: 25px;
        height: 25px;
        margin-left: 20px;
        cursor: pointer;
      }

      p {
        position: absolute;
        top: 0;
        right: 0;
        width: 80px;
        height: 55px;
        background-color: #64b6a8;
        text-align: center;
        line-height: 55px;
        font-size: 24px;
        cursor: pointer;
        color: #ffffff;
      }
    }

    .download {
      width: 200px;
      height: 50px;
      background-color: #64b6a8;
      border-radius: 6px;
      color: #fff;
      text-align: center;
      line-height: 50px;
    }

    .but {
      display: inline-block;
      width: 200px;
      height: 50px;
      background: #64b6a8;
      border-radius: 6px;
      text-align: center;
      line-height: 50px;
      color: #fff;
    }
  }
}

.helpFriends {
  width: 1200px;
  margin: 0 auto;
  margin-top: 50px;

  .helpFriends_title {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .helpFriends_title_left {
      display: flex;
      align-items: center;

      .helpFriends_title_left_img {
        width: 112px;
        height: 112px;
        overflow: hidden;
        border-radius: 50%;
      }

      .helpFriends_title_left_span {
        font-size: 36px;
        font-weight: 400;
        color: #333333;
        margin-left: 40px;
      }
    }

    .helpFriends_title_right {
      cursor: pointer;
      display: flex;
      justify-content: space-between;
      cursor: pointer;
    }
  }

  .helpFriends_article {
    margin-top: 34px;

    .helpFriends_article_text {
      font-size: 26px;
      font-weight: 500;
      color: #333333;
      line-height: 30px;
      cursor: pointer;
    }

    .helpFriends_article_active {
      cursor: pointer;
      font-size: 26px;
      font-weight: 500;
      color: #333333;
      line-height: 30px;
      // overflow: hidden;
      // text-overflow: ellipsis;
      // display: -webkit-box;
      // -webkit-box-orient: vertical;
      // -webkit-line-clamp: 4;
    }

    .unfold {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      font-size: 26px;
      font-weight: 400;
      color: #64b6a8;

      span {
        cursor: pointer;
      }

      .unfold_img {
        width: 20px;
        height: 20px;
        cursor: pointer;
      }
    }

    .unfold_yc {
      display: none;
    }
  }

  .img_one {
    width: 100%;
    height: 290px;
    margin-top: 30px;

    img {
      object-fit: cover;
      width: 100%;
      height: 100%;
      border-radius: 8px;
    }
  }

  .img_two {
    width: 100%;
    height: 290px;
    display: flex;
    justify-content: space-between;
    margin-top: 30px;

    img {
      object-fit: cover;
      width: 48%;
      height: 100%;
      border-radius: 8px;
    }
  }

  .img_three {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-top: 30px;

    img {
      object-fit: cover;
      width: 30%;
      height: 100%;
      border-radius: 8px;
      margin-bottom: 20px;
    }
  }

  .video {
    width: 100%;
    height: 290px;
    margin-top: 30px;

    video {
      width: 100%;
      height: 100%;
      border-radius: 8px;
    }
  }

  .byq_bottom {
    display: flex;
    justify-content: space-between;
    margin-top: 30px;
    align-items: center;

    .byq_bottom_right {
      display: flex;
      align-items: center;

      .byq_bottom_right_item {
        display: flex;
        align-items: center;
        font-size: 26px;
        font-weight: 400;
        color: #333333;
        margin-right: 35px;

        .byq_bottom_right_item_img {
          width: 30px;
          height: 30px;
          margin-right: 10px;
        }
      }
    }
  }
}

.fenye {
  width: 100%;
  height: 50px;
  text-align: center;
  margin: 60px 0px;

  /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #64b6a8;
  }
}

/deep/.el-rate__icon {
  font-size: 30px;
}

.gotop {
  position: fixed;
  width: 85px;
  height: 33px;
  line-height: 34px;
  box-sizing: border-box;
  padding-left: 30px;
  right: 15px;
  right: calc((100vw / 2) - 600px);
  bottom: 77px;
  background-color: #fff;
  border-radius: 17px;
  font-size: 12px;
  box-shadow: 0px 0px 36px rgba(0, 0, 0, 0.16);
  color: #000;
  z-index: 9999999;
  cursor: pointer;

  img {
    position: absolute;
    left: 5px;
    top: 5px;
    width: 23px;
    height: 23px;
  }
}</style>
